home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / UNIX Cracking / MacCracSource.sit / MacCrac.source / Source / Mac Environment.c < prev    next >
Text File  |  1995-02-08  |  6KB  |  283 lines

  1. /*****
  2.  CracMac Environment
  3. *****/
  4.  
  5. #include "Traps.h"
  6. #include "crack.h"
  7. #include <displays.h>
  8. #include <sound.h>
  9.  
  10. #define NIL        0L
  11.  
  12.  
  13. #define MENUNUM     128        /* resedit ID of menu */
  14. #define ABOUTDI        128        /* resedit ID of the About Dialog */
  15. #define SETTINGSDI    129        /* resedit ID of the New Game Dialogue */
  16.  
  17. #define APPLEM        128        /* apple menu */
  18. #define ABOUTI        1        /* the about Item */
  19. #define FILEM        129        /* file menu */
  20. #define QUITI        1        /* the quit item */
  21.  
  22. #define EDITM        130        /* the edit menu */
  23. #define CUTI        1
  24. #define COPYI        2
  25. #define PASTEI        3
  26. #define CLEARI        4
  27.  
  28. #define CRACKM        131        /* crack menu */
  29. #define DOITI        1
  30. #define SETTINGSI    2
  31. #define HELPI        3
  32.  
  33. #define FOREGROUNDW 128     /* the foreground window*/
  34.  
  35. static const char kEnter    = (char) 0x03;
  36. static const char kReturn    = (char) 0x0D;
  37.  
  38. extern DoIt();
  39. extern SysLog();
  40. extern fcrypt();
  41. extern Log();
  42.  
  43.  
  44. void closeForeground()
  45. {
  46. DisposeWindow(FrontWindow());
  47. }
  48.  
  49. void initForeground()
  50. {
  51. WindowPtr theWindow;
  52.  
  53. theWindow = GetNewWindow (FOREGROUNDW, NIL, (WindowPtr) -1);
  54. SetPort(theWindow);
  55. TextMode (srcCopy);
  56. TextSize(10);
  57. if (foreground_bool == TRUE)
  58.    SysLog("MacCrac Session Started.      No passwords guessed.");
  59. ForeColor(blackColor);
  60. MoveTo(0,10);
  61. }
  62.  
  63. void DoSettings()
  64. {
  65.     DialogPtr    SettingsDialog;
  66.     short        itemHit;
  67.     EventRecord theEvent;
  68.     short        itemType;
  69.     Handle        itemHandle;
  70.     Rect    itemRect;
  71.  
  72.     SettingsDialog = GetNewDialog(SETTINGSDI, NIL, (WindowPtr) -1);
  73.  
  74. /* load in old values -  I'm using a new dialog every time... */
  75.  
  76.     GetDialogItem(SettingsDialog, 1, &itemType, &itemHandle, &itemRect);
  77.     SetControlValue((ControlHandle)itemHandle, foreground_bool);
  78.     GetDialogItem(SettingsDialog, 2, &itemType, &itemHandle, &itemRect);
  79.     SetControlValue((ControlHandle)itemHandle, verbose_bool);
  80.     GetDialogItem(SettingsDialog, 3, &itemType, &itemHandle, &itemRect);
  81.     SetControlValue((ControlHandle)itemHandle, recover_bool);
  82.  
  83.  
  84.  
  85.     do {
  86.        ModalDialog(NIL, &itemHit);
  87.        switch (itemHit)
  88.         {
  89.         case 1:
  90.                     GetDialogItem(SettingsDialog, itemHit, &itemType, &itemHandle, 
  91.                               &itemRect);
  92.                     foreground_bool = GetControlValue((ControlHandle)itemHandle);
  93.                     foreground_bool = 1 - foreground_bool;
  94.                     SetControlValue((ControlHandle)itemHandle, foreground_bool);
  95.                     break;
  96.         case 2:
  97.                     GetDialogItem(SettingsDialog, itemHit, &itemType, &itemHandle, 
  98.                               &itemRect);
  99.                     verbose_bool = GetControlValue((ControlHandle)itemHandle);
  100.                     verbose_bool = 1 - verbose_bool;
  101.                     SetControlValue((ControlHandle)itemHandle, verbose_bool);
  102.                     break;
  103.         case 3:
  104.                     GetDialogItem(SettingsDialog, itemHit, &itemType, &itemHandle, 
  105.                               &itemRect);
  106.                     recover_bool = GetControlValue((ControlHandle)itemHandle);
  107.                     recover_bool = 1 - recover_bool;
  108.                     SetControlValue((ControlHandle)itemHandle, recover_bool);
  109.                     break;
  110.     }
  111.  
  112.  
  113.      }  while (itemHit != 4);
  114.     DisposeDialog(SettingsDialog);
  115.  
  116.  
  117. }
  118.  
  119.  
  120. /****
  121. This initializes everything.
  122. ****/
  123.  
  124. void InitMac(void)
  125.  
  126. {
  127.  
  128. /*DialogPtr (AboutDialog); */
  129.  
  130.  
  131.     InitGraf(&qd.thePort);
  132.     InitWindows();
  133.     InitDialogs(NULL);
  134.   /*  AboutDialog = GetNewDialog(ABOUTDI, NIL, (WindowPtr) -1); */
  135.  
  136.     InitFonts();
  137.     FlushEvents(everyEvent - osMask - diskMask, 0);
  138.     InitMenus();
  139.     TEInit();
  140.  
  141.     InitCursor();
  142.  
  143.     MaxApplZone();
  144.     MoreMasters();
  145. /*    DisposeDialog(AboutDialog); */
  146. }
  147.  
  148.  
  149. void do_menu(void)
  150. {
  151. Handle menuBar;
  152.  
  153.  
  154.  
  155.     menuBar = GetNewMBar(MENUNUM);
  156.     SetMenuBar(menuBar);                    
  157.     DisposHandle(menuBar); 
  158.     AddResMenu(GetMHandle(APPLEM), 'DRVR');     /*Add DA names to Apple menu */
  159. /*    AdjustMenus(); */
  160.     DrawMenuBar();
  161.  
  162. }
  163.  
  164. /* ShowAbout - shows the about dialogue box.. a modal dialogue */
  165.  
  166. void ShowAbout(void)
  167. {
  168.     DialogPtr    AboutDialog;
  169.     short        itemHit;
  170.     SndChannelPtr theSoundChannelP = NIL;
  171.     Handle theSoundH = NIL;
  172.     OSErr err;
  173.  
  174.     AboutDialog = GetNewDialog(ABOUTDI, NIL, (WindowPtr) -1);
  175.     theSoundH = GetResource('snd ', 128);
  176.     if (theSoundH != nil) {
  177.         err = SndNewChannel(&theSoundChannelP, sampledSynth, initMono,
  178.             nil);
  179.     if (err == noErr)
  180.             SndPlay(theSoundChannelP, (SndListHandle)theSoundH, true);
  181.             }
  182.     ModalDialog(NIL, &itemHit);
  183.     SndDisposeChannel(theSoundChannelP, true);
  184.     theSoundChannelP = nil;
  185.     ReleaseResource(theSoundH);
  186.     theSoundH = nil;
  187.     DisposeDialog(AboutDialog);
  188. }
  189.  
  190.  
  191. /*  HandleMenu -- put the menu choices here
  192. */
  193.  
  194. void HandleMenu(long mselect)
  195. {
  196.  
  197.  
  198. int             menuID = HiWord(mselect);
  199. int                menuItem = LoWord(mselect);
  200. Str255            name;
  201. GrafPtr         savePort;
  202.  
  203.  
  204.                 switch (menuID)
  205.                     {
  206.                     case APPLEM:
  207.                         if (menuItem == ABOUTI) { ShowAbout(); break;}
  208.                     GetPort(&savePort);
  209.                     GetItem(GetMHandle(APPLEM), menuItem, name);
  210.                     (void) OpenDeskAcc(name);
  211.                     SetPort(savePort);       /* run the DA and return to the prog */
  212.                     break;
  213.     
  214.                     
  215.                     case FILEM:
  216.                         if (menuItem == QUITI) ExitToShell();
  217.                         break;
  218.  
  219.                     case CRACKM:
  220.                         if (menuItem == DOITI) DoIt();
  221.                         if (menuItem == SETTINGSI) DoSettings();
  222.                         break;
  223.                     
  224.                     }
  225. }
  226.  
  227. /* HandleMouseDown  takes a mousepress and does whatever it should-- in this case,
  228. the menu bar stuff */
  229.  
  230. void HandleMouseDown (EventRecord *theEvent)
  231. {
  232.  
  233.  WindowPtr         theWindow;
  234.  int            windowCode =  FindWindow (theEvent->where, &theWindow);
  235.  
  236.     switch(windowCode)
  237.         {
  238.         
  239.             case inSysWindow:
  240.                 SystemClick (theEvent, theWindow);
  241.                 break;
  242.                 
  243.             case inMenuBar:
  244.                 HandleMenu(MenuSelect(theEvent->where));
  245.                 break;
  246.                 
  247.                 
  248.                 
  249.         }
  250. }
  251.  
  252. /* Handle Event - does the events */
  253.  
  254. void HandleEvent(void)
  255. {
  256.  
  257.     int            ok;
  258.     EventRecord    theEvent;
  259.  
  260.  
  261.     HiliteMenu(0);
  262.     SystemTask();
  263.     
  264.     ok = GetNextEvent (everyEvent, &theEvent);
  265.     if (ok)
  266.         switch (theEvent.what)
  267.         {
  268.         case mouseDown:
  269.             HandleMouseDown(&theEvent);
  270.             break;
  271.             
  272.         case keyDown:
  273.         case autoKey:
  274.         
  275.         case updateEvt:
  276.         case activateEvt:
  277.         break;
  278.         }
  279.         
  280.         
  281. }
  282.  
  283.